package com.skyon.rule.res.utils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import net.sf.cglib.beans.BeanMap;

public class ReflectGetValue {
    /**
     * 取出bean 属性和值
     * @param obj
     * @return
     * @throws Exception
     */
    public static Map<String,Object> getFileValue(Object obj) throws Exception{
    	BeanMap map = BeanMap.create(obj);
    	map.setBean(obj);
        return map;
    }
    /**
     * 设置bean 属性值
     * @param map
     * @param bean
     * @throws Exception
     */
    public static void setFieldValue(Map<String, Object> map, Object bean) throws Exception{
    	BeanMap beanMap = BeanMap.create(bean);
    	beanMap.putAll(map);
    }
    //测试方法
    public static void main(String[] args) {
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("yi", "michael");
            map.put("san", new Double(27));
            map.put("si", new BigDecimal("1.29932"));

	        Class<?> c = Class.forName("com.skyon.rule.res.client.InvokeBean");
	        Object invBean = c.newInstance();
            ReflectGetValue.setFieldValue(map, invBean);
            Map<String, Object> m= ReflectGetValue.getFileValue(invBean);
            System.out.println(m.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}